from rest_framework import serializers
from orders.models import OrderInfo,OrderGoods
from goods.models import SKU

#1,获取订单序列化器
class OrdersSerializer(serializers.ModelSerializer):
    class Meta:
        model = OrderInfo
        fields = "__all__"


#2,获取单个订单序列化器
class SKUSerializer(serializers.ModelSerializer):
    class Meta:
        model = SKU
        fields = "__all__"

class OrderGoodsSerializer(serializers.ModelSerializer):

    #1,指定sku
    sku = SKUSerializer(read_only=True)

    class Meta:
        model = OrderGoods
        fields = "__all__"


class OrderSerializer(serializers.ModelSerializer):

    #1,订单商品
    skus =  OrderGoodsSerializer(read_only=True,many=True)

    class Meta:
        model = OrderInfo
        fields = "__all__"
